﻿import { RedDotType } from '../../../Data/Types';

// 红点信息类
export class RedDotInfo {
  // 红点名
  redDotName: string;

  //作用域
  target: unknown;

  // 红点刷新委托(理论上只会绑定一个回调)
  refreshDelegate: (dotName: string, result: number, type: RedDotType) => void;

  // 构造函数
  constructor(redDotName: string) {
    this.redDotName = redDotName;
  }

  // 红点对象刷新绑定
  Bind(refreshDelegate: (dotName: string, result: number, type: RedDotType) => void, target: unknown) {
    if (this.refreshDelegate != null) {
      // Debug.LogError($"红点名:{RedDotName}重复绑定刷新回调!");
    }
    this.refreshDelegate = refreshDelegate;
    this.target = target;
  }

  // 红点对象解绑定
  UnBind() {
    this.refreshDelegate = null;
  }

  // 触发刷新结
  triggerUpdate(result: number, redDotType: RedDotType) {
    if (this.refreshDelegate != null) {
      this.refreshDelegate.call(this.target, this.redDotName, result, redDotType);
    }
  }
}
